/*
 * util.c
 *
 *  Created on: Dec 4, 2012
 *      Author: root
 */


#include "tutorfs.h"

int _get_dentry_path(char *path, int size, struct dentry *dentry) {
	char *name;
	int name_len, parent_size = 0, isroot;

	name = dentry->d_name.name;
	if(!strcmp(name, "/"))
		return 0;

	parent_size = _get_dentry_path(path, size, dentry->d_parent);
	name_len = strlen(name);

	if (parent_size >= 0 && name_len + parent_size < size) {

		strcat(path, "/");
		strcat(path, name);
		return parent_size + name_len;
	}

	return -1;
}

int get_dentry_path(char *path, int size, struct dentry *dentry) {
	memset(path, 0, size);
	return _get_dentry_path(path, size, dentry);
}
